/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.verolux.soft.debaraz.controller;

import com.verolux.soft.debaraz.ApplicationException;
import com.verolux.soft.debaraz.bean.FirstBean;
import com.verolux.soft.debaraz.service.FirstService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author ut1e8p
 */
@Controller
@RequestMapping("/first")
public class FirstController {

    private static Logger logger = Logger.getLogger(FirstController.class);

    @Autowired
    private FirstService firstService;

    /**
     *
     * @return
     */
    @RequestMapping ("/view.do")
    public ModelAndView initializeForm(){
        FirstBean firstBean = new FirstBean();
        return new ModelAndView("firstJsp", "firstBean", firstBean);
    }

    /**
     *
     * @return
     */
    @RequestMapping ("/save.do")
    public ModelAndView save(@ModelAttribute FirstBean firstBean){

        logger.info(firstBean);

        try {
            firstService.insert(firstBean);
        } catch (ApplicationException e) {
            logger.error(e.getMessage(), e);
        }

        FirstBean bean = new FirstBean();
        return new ModelAndView("firstJsp", "firstBean", bean);
    }

}
